﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ComLib.ComFun;
using ComLib.ConfigService;
using LogLib;
using ComLib.ComType;

namespace ComLib.ConfigClass
{
    public class WorkFlowOption : IniConfigBase
    {
        public WorkFlowOption()
            : base()
        {
        }

        /// <summary>
        /// 业务流程类型
        /// </summary>
        private UserApplyAction _applyType = UserApplyAction.OnlyTakePhoto;
        public UserApplyAction ApplyType
        {
            get { return _applyType; }
            set { _applyType = value; }
        }

        /// <summary>
        /// 启用手写签名
        /// </summary>
        private bool _signature = true;
        public bool Signature
        {
            get { return _signature; }
            set { _signature = value; }
        }

        /// <summary>
        /// 启用指纹采集
        /// </summary>
        private bool _capFinger = true;
        public bool CapFinger
        {
            get { return _capFinger; }
            set { _capFinger = value; }
        }

        /// <summary>
        /// 启用快递方式填写
        /// </summary>
        private bool _receiveWay = true;
        public bool ReceiveWay
        {
            get { return _receiveWay; }
            set { _receiveWay = value; }
        }

        /// <summary>
        /// 启用快递方式填写
        /// </summary>
        private bool _highCapture = true;
        public bool HightCapture
        {
            get { return _highCapture; }
            set { _highCapture = value; }
        }

        public override bool Save()
        {
            base.Save();
            SaveField("CapFinger", _capFinger);
            SaveField("Signature", _signature);
            SaveField("ApplyType", _applyType);
            SaveField("ReceiveWay", _receiveWay);
            SaveField("HightCapture", _highCapture);
            return true;
        }

        public override bool Load()
        {
            base.Load();
            try
            {
                _signature = LoadBoolenValue("Signature");
                _receiveWay = LoadBoolenValue("ReceiveWay");
                _capFinger = LoadBoolenValue("CapFinger");
                _highCapture = LoadBoolenValue("HightCapture");
                _applyType = LoadEnumValue<UserApplyAction>("ApplyType");
            }
            catch (Exception ex)
            {
                ErrorMessage = string.Format("配置文件{0}加载错误:\n\t{1}", ConfigFilePath, ex.Message);
                Log.WriteException(ex.ToString());
                return false;
            }
            return true;
        }

        public override string ToString()
        {
            StringBuilder builder = new StringBuilder("业务流程选项配置: ");
            FillEnabledStringDelegate FillString =
                (string field, bool val) =>
                {
                    builder.Append("[");
                    builder.Append(field);
                    builder.Append("]: ");
                    builder.Append(val ? "启用" : "未启用");
                };
            FillFieldValueStringDelegate FillStringT =
                (string field, object val) =>
                {
                    builder.Append("[");
                    builder.Append(field);
                    builder.Append("]: ");
                    builder.Append(val.ToString());
                };
            FillString("手写签名", _signature);
            FillString("填写取证方式", _receiveWay);
            FillString("采集指纹", _capFinger);
            FillString("高拍", _highCapture);
            FillStringT("业务流程", _applyType);
            return builder.ToString();
        }
    }
}
